package com.edu.koTA07.adapter;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.edu.koTA07.bean.CustomerBean;
import com.edu.koTA07.takingOrder.R;

public class CustomersListAdapter extends BaseAdapter {

	ArrayList<CustomerBean> customers;
	Context context;
	
	public CustomersListAdapter(Context context,
			ArrayList<CustomerBean> customers) {
		// TODO Auto-generated constructor stub
		super();
		inflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.customers = customers;
		this.context = context;
	}
	private static LayoutInflater inflater = null;

	public int getCount() {
		return customers.size();
	}

	public CustomerBean getItem(int position) {
		return (null == customers) ? null : customers.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
	
	class ViewHolder {
		TextView textLine;
	     ImageView iconLine;
	     Button buttonLine;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		View vi = convertView;
		
		if (convertView == null) {
			vi = inflater.inflate(R.layout.content_toko, null);
			holder = new ViewHolder();
			holder.textLine = (TextView) vi.findViewById(R.id.textLine);
			vi.setTag(holder);
		}
		else 
			holder = (ViewHolder) vi.getTag();
		
		String namaToko = customers.get(position).getNamaToko();
		holder.textLine.setText(namaToko);
		return vi;
	}
	public void forceReload() {
		notifyDataSetChanged();
	}	
}
